import pymysql

class Todo:
	def __init__(self,host = 'localhost',user = 'root',password = '',db = 'mydemo',charset = 'utf8'):
		self.db = pymysql.connect(host = host,user = user,password = password,db = db,charset = charset)
		self.cursor = self.db.cursor()

	def FindAll(self,sql):
		self.cursor.execute(sql)
		self.data = self.cursor.fetchall()
		return self.data

	def Del(self,sql):
		try:
			self.cursor.execute(sql)
			self.db.commit()
		except Exception as err:
			print('SQL执行错误!原因:',err)
			self.db.rollback()

	def Insert(self,sql):
		try:
			self.cursor.execute(sql)
			self.db.commit()
		except Exception as err:
			print('SQL执行错误!原因:',err)
			self.db.rollback()

	def __del__(self):
		self.db.close()




